/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gamedsl2.impl;

import gamedsl2.Entity;
import gamedsl2.Event;
import gamedsl2.Gamedsl2Package;
import gamedsl2.State;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gamedsl2.impl.EventImpl#getMessage <em>Message</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getName <em>Name</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getType <em>Type</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getTriggerEntity <em>Trigger Entity</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getSubscriberEntities <em>Subscriber Entities</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getTriggerGameState <em>Trigger Game State</em>}</li>
 *   <li>{@link gamedsl2.impl.EventImpl#getSubscriberGameStates <em>Subscriber Game States</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EventImpl extends EObjectImpl implements Event {
	/**
	 * The default value of the '{@link #getMessage() <em>Message</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessage()
	 * @generated
	 * @ordered
	 */
	protected static final String MESSAGE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getMessage() <em>Message</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessage()
	 * @generated
	 * @ordered
	 */
	protected String message = MESSAGE_EDEFAULT;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final String TYPE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected String type = TYPE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getTriggerEntity() <em>Trigger Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTriggerEntity()
	 * @generated
	 * @ordered
	 */
	protected Entity triggerEntity;

	/**
	 * The cached value of the '{@link #getSubscriberEntities() <em>Subscriber Entities</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubscriberEntities()
	 * @generated
	 * @ordered
	 */
	protected EList<Entity> subscriberEntities;

	/**
	 * The cached value of the '{@link #getTriggerGameState() <em>Trigger Game State</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTriggerGameState()
	 * @generated
	 * @ordered
	 */
	protected State triggerGameState;

	/**
	 * The cached value of the '{@link #getSubscriberGameStates() <em>Subscriber Game States</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubscriberGameStates()
	 * @generated
	 * @ordered
	 */
	protected EList<State> subscriberGameStates;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Gamedsl2Package.Literals.EVENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMessage(String newMessage) {
		String oldMessage = message;
		message = newMessage;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__MESSAGE, oldMessage, message));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(String newType) {
		String oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity getTriggerEntity() {
		if (triggerEntity != null && triggerEntity.eIsProxy()) {
			InternalEObject oldTriggerEntity = (InternalEObject)triggerEntity;
			triggerEntity = (Entity)eResolveProxy(oldTriggerEntity);
			if (triggerEntity != oldTriggerEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, Gamedsl2Package.EVENT__TRIGGER_ENTITY, oldTriggerEntity, triggerEntity));
			}
		}
		return triggerEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity basicGetTriggerEntity() {
		return triggerEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTriggerEntity(Entity newTriggerEntity, NotificationChain msgs) {
		Entity oldTriggerEntity = triggerEntity;
		triggerEntity = newTriggerEntity;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__TRIGGER_ENTITY, oldTriggerEntity, newTriggerEntity);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTriggerEntity(Entity newTriggerEntity) {
		if (newTriggerEntity != triggerEntity) {
			NotificationChain msgs = null;
			if (triggerEntity != null)
				msgs = ((InternalEObject)triggerEntity).eInverseRemove(this, Gamedsl2Package.ENTITY__ENTITY_TRIGGERS, Entity.class, msgs);
			if (newTriggerEntity != null)
				msgs = ((InternalEObject)newTriggerEntity).eInverseAdd(this, Gamedsl2Package.ENTITY__ENTITY_TRIGGERS, Entity.class, msgs);
			msgs = basicSetTriggerEntity(newTriggerEntity, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__TRIGGER_ENTITY, newTriggerEntity, newTriggerEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Entity> getSubscriberEntities() {
		if (subscriberEntities == null) {
			subscriberEntities = new EObjectWithInverseResolvingEList.ManyInverse<Entity>(Entity.class, this, Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES, Gamedsl2Package.ENTITY__ENTITY_SUBSCRIBERS);
		}
		return subscriberEntities;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State getTriggerGameState() {
		if (triggerGameState != null && triggerGameState.eIsProxy()) {
			InternalEObject oldTriggerGameState = (InternalEObject)triggerGameState;
			triggerGameState = (State)eResolveProxy(oldTriggerGameState);
			if (triggerGameState != oldTriggerGameState) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, Gamedsl2Package.EVENT__TRIGGER_GAME_STATE, oldTriggerGameState, triggerGameState));
			}
		}
		return triggerGameState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State basicGetTriggerGameState() {
		return triggerGameState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTriggerGameState(State newTriggerGameState, NotificationChain msgs) {
		State oldTriggerGameState = triggerGameState;
		triggerGameState = newTriggerGameState;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__TRIGGER_GAME_STATE, oldTriggerGameState, newTriggerGameState);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTriggerGameState(State newTriggerGameState) {
		if (newTriggerGameState != triggerGameState) {
			NotificationChain msgs = null;
			if (triggerGameState != null)
				msgs = ((InternalEObject)triggerGameState).eInverseRemove(this, Gamedsl2Package.STATE__GAME_STATE_TRIGGERS, State.class, msgs);
			if (newTriggerGameState != null)
				msgs = ((InternalEObject)newTriggerGameState).eInverseAdd(this, Gamedsl2Package.STATE__GAME_STATE_TRIGGERS, State.class, msgs);
			msgs = basicSetTriggerGameState(newTriggerGameState, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.EVENT__TRIGGER_GAME_STATE, newTriggerGameState, newTriggerGameState));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<State> getSubscriberGameStates() {
		if (subscriberGameStates == null) {
			subscriberGameStates = new EObjectWithInverseResolvingEList.ManyInverse<State>(State.class, this, Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES, Gamedsl2Package.STATE__GAME_STATE_SUBSCRIBERS);
		}
		return subscriberGameStates;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				if (triggerEntity != null)
					msgs = ((InternalEObject)triggerEntity).eInverseRemove(this, Gamedsl2Package.ENTITY__ENTITY_TRIGGERS, Entity.class, msgs);
				return basicSetTriggerEntity((Entity)otherEnd, msgs);
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSubscriberEntities()).basicAdd(otherEnd, msgs);
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				if (triggerGameState != null)
					msgs = ((InternalEObject)triggerGameState).eInverseRemove(this, Gamedsl2Package.STATE__GAME_STATE_TRIGGERS, State.class, msgs);
				return basicSetTriggerGameState((State)otherEnd, msgs);
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSubscriberGameStates()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				return basicSetTriggerEntity(null, msgs);
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				return ((InternalEList<?>)getSubscriberEntities()).basicRemove(otherEnd, msgs);
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				return basicSetTriggerGameState(null, msgs);
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				return ((InternalEList<?>)getSubscriberGameStates()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__MESSAGE:
				return getMessage();
			case Gamedsl2Package.EVENT__NAME:
				return getName();
			case Gamedsl2Package.EVENT__TYPE:
				return getType();
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				if (resolve) return getTriggerEntity();
				return basicGetTriggerEntity();
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				return getSubscriberEntities();
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				if (resolve) return getTriggerGameState();
				return basicGetTriggerGameState();
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				return getSubscriberGameStates();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__MESSAGE:
				setMessage((String)newValue);
				return;
			case Gamedsl2Package.EVENT__NAME:
				setName((String)newValue);
				return;
			case Gamedsl2Package.EVENT__TYPE:
				setType((String)newValue);
				return;
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				setTriggerEntity((Entity)newValue);
				return;
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				getSubscriberEntities().clear();
				getSubscriberEntities().addAll((Collection<? extends Entity>)newValue);
				return;
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				setTriggerGameState((State)newValue);
				return;
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				getSubscriberGameStates().clear();
				getSubscriberGameStates().addAll((Collection<? extends State>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__MESSAGE:
				setMessage(MESSAGE_EDEFAULT);
				return;
			case Gamedsl2Package.EVENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case Gamedsl2Package.EVENT__TYPE:
				setType(TYPE_EDEFAULT);
				return;
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				setTriggerEntity((Entity)null);
				return;
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				getSubscriberEntities().clear();
				return;
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				setTriggerGameState((State)null);
				return;
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				getSubscriberGameStates().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.EVENT__MESSAGE:
				return MESSAGE_EDEFAULT == null ? message != null : !MESSAGE_EDEFAULT.equals(message);
			case Gamedsl2Package.EVENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case Gamedsl2Package.EVENT__TYPE:
				return TYPE_EDEFAULT == null ? type != null : !TYPE_EDEFAULT.equals(type);
			case Gamedsl2Package.EVENT__TRIGGER_ENTITY:
				return triggerEntity != null;
			case Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES:
				return subscriberEntities != null && !subscriberEntities.isEmpty();
			case Gamedsl2Package.EVENT__TRIGGER_GAME_STATE:
				return triggerGameState != null;
			case Gamedsl2Package.EVENT__SUBSCRIBER_GAME_STATES:
				return subscriberGameStates != null && !subscriberGameStates.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (message: ");
		result.append(message);
		result.append(", name: ");
		result.append(name);
		result.append(", type: ");
		result.append(type);
		result.append(')');
		return result.toString();
	}

} //EventImpl
